﻿using SWENAssignment.Sophia.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SWENAssignment.Sophia
{
    public partial class retrieveRoomReservation : System.Web.UI.Page
    {

        string r;
        protected void Page_Load(object sender, EventArgs e)
        {
            lblRoomNum.Text = Request.QueryString["roomNum"];
            r = Request.QueryString["roomReservation"];
            if (r != null)
            {
                lblReservationID.Text = r;
                roomReservation rr2 = DBmanager.getRoomReservationByID(lblReservationID.Text);

                lblReservationID.Text = rr2.ReservationID;
                lblCustomerID.Text = rr2.CustomerID;
                lblNumOfAdults.Text = Convert.ToString(rr2.NumOfAdults);
                lblNumOfChildren.Text = Convert.ToString(rr2.NumOfChildren);
                lblPrefRoomType.Text = rr2.PreferredRoomType;
                lblPrefBedType.Text = rr2.PreferredBedType;
                lblSmokingOrNot.Text = rr2.SmokingOrNot;
                lblReservationStatus.Text = rr2.ReservationStatus;
            }
            
    
      
        }
        

        protected void btnBackToMP_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Sophia/RANBMainPage.aspx");
        }

        protected void lbtnAddRes_Click(object sender, EventArgs e)
        {
            string querystring = "roomNum=" + lblRoomNum.Text;
            Server.Transfer("~/Sophia/GuestExistOrNot.aspx?" + querystring);
        }

        protected void lbtnEditRes_Click(object sender, EventArgs e)
        {
            string querystring = "reservationID=" + lblReservationID.Text;
            Server.Transfer("~/Sophia/editRoomReservation.aspx?" + querystring);
        }

        protected void lbtnCheckIn_Click(object sender, EventArgs e)
        {
            string querystring = "customerID=" + lblCustomerID.Text + "&reservationID=" + lblReservationID.Text + "&numOfAdults=" + lblNumOfAdults.Text + "&numOfChildren=" + lblNumOfChildren.Text  + "&preferredRoomType=" + lblPrefRoomType.Text + "&roomNum=" + lblRoomNum.Text;
            Server.Transfer("~/Sophia/addCheckInDetails.aspx?" + querystring);
        }

        protected void lbtnCancel_Click(object sender, EventArgs e)
        {
            DBmanager.UpdateRoomStatus(lblRoomNum.Text, "vacant", "");
            if (DBmanager.deleteReservation(lblReservationID.Text) == 1)
            {
               
                string querystring = "roomNum=" + lblRoomNum.Text + "&roomReservation=";
                Server.Transfer("~/Sophia/retrieveRoomReservation.aspx?" + querystring);
            }
        }

    }
}
